(function(app){
	app
		.controller("content_02_2_inputCtrl",["$scope","myFactory",'$http','$stateParams','$state',"$q",'$timeout','$location','$ionicHistory',function($scope,myFactory,$http,$stateParams,$state,$q,$timeout,$location,$ionicHistory){

			//接收参数
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var searchParam = $stateParams.searchParam;
			var policyData;//保单详情
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var item02_2="";
			//参数绑定
			$scope.chdrnum01 =  $stateParams.chdrnum01;
			$scope.readFlag = true;//阅读协议标志，默认为true
			var token=sessionStorage.getItem("token");
			$scope.data = {
				radioFlag: true
			},
					
			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
		
			//返回函数
			$scope.goBack = function () {
				myFactory.goBack();
			}
			//客户须知弹框
			$scope.tipOpen = function(){
				modal('open','tip_model','policyWindowOn02_2Input');
			}
			$scope.tipClose = function(){
				modal('close','tip_model','policyWindowOn02_2Input');
			}
			//页面同意阅读协议复选框部分
			$scope.changeReadFlag = function(){
				$scope.readFlag = !$scope.readFlag;
			}
			//保单详情弹窗
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn02_2Input','policyWindowOn02_2Input','policyCloseXOn02_2Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化时候查询保单详情
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}
			
			//保单详情弹窗关闭函数
			$scope.policyCancelOn02_2Input = function(){
				modal('close','policyModalOn02_2Input','policyWindowOn02_2Input','policyCloseXOn02_2Input');
			}

			//关闭遮罩
			$scope.overwindowClose = function(){
				//$(".overwindow").show();
				$(".overwindow").hide();
				$(".overmodal").hide();
			}
/**********************************************初始化函数begin********************************/
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						$scope.item02_2 = response.data.data.modelMap.item02_2;
						item02_2 = response.data.data.modelMap.item02_2;
						initFlag=true;//标识初始化成功
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
/**********************************************初始化函数end***************************************/
			$scope.nextStep = function(){
				//判断是否初始化完成了，如果失败，不予进入项目
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return;
				}

				var name=item02_2.accNameCn;
				var bank=item02_2.bankName;
				var cark=item02_2.reBankAccNo;
				if(!name&&!bank&&!cark){
					$("#nextBtn").addClass("disabled");
					myFactory.alert("","当前续期缴费方式非银行转账，不能受理此变更项目！","info");
					return false;
				}

				//检测查阅弹框
		        var readImageFlag = $("#readImageFlag").val();
	    		if(readImageFlag=="false"){
	    			$.alert({
						 title: '',
						 text: '请阅读《申请须知》！',
						 onOK: function () {
						 //点击确认
						 }
					});
	    			return;
	    		}else{
					$ionicHistory.clearCache().then(function(){ 
						$state.go('content_check_main',{
							itemId:itemId,
							item:$scope.item02_2,
							chdrnum01:chdrnum01,
							chdrcoy:chdrcoy
						});
					})
	    		}
			}
			
		}]);
	
		//指针弹窗，不同APP，要提取到app.controller("content_36_inputCtrl")后面
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});
})(app)